{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1169
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	i,n:longint;
	a:array[0..100010] of longint;
 
procedure siftup(i:longint);
 
var 
	tt:longint;
 
begin
while (i>1) and (a[i div 2]<a[i]) do begin
	tt:=a[i];
  a[i]:=a[i div 2];
	a[i div 2]:=tt;
  i:=i div 2;
end;
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do begin
	read(a[i]);
	siftup(i);
end;
for i:=1 to n do
	write(a[i],' ');
end.